package com.zxy.cover.controller;

import java.util.Arrays;
import java.util.Date;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import com.zxy.cover.entity.RecordEntity;
import com.zxy.cover.service.RecordService;
import com.zxy.common.utils.PageUtils;
import com.zxy.common.utils.R;

import javax.xml.crypto.Data;


/**
 * 求房信息表
 *
 * @author zb
 * @email sunlightcs@gmail.com
 * @date 2022-04-26 15:07:03
 */
@RestController
@RequestMapping("cover/record")
@CrossOrigin
public class RecordController {
    @Autowired
    private RecordService recordService;

    /**
     * 列表
     */
    @RequestMapping("/list")
    public R list(@RequestParam Map<String, Object> params){
        PageUtils page = recordService.queryPage(params);

        return R.ok().put("page", page);
    }


    /**
     * 信息
     */
    @RequestMapping("/info/{id}")
    public R info(@PathVariable("id") Integer id){
		RecordEntity record = recordService.getById(id);

        return R.ok().put("record", record);
    }

    /**
     * 保存
     */
    @RequestMapping("/save")
    public R save(@RequestBody RecordEntity record){
        record.setStart( 0 );
		recordService.save(record);

        return R.ok();
    }

    /**
     * 修改
     */
    @RequestMapping("/update")
    public R update(@RequestBody RecordEntity record){
        Date date = new Date();
        record.setUpdatedAt( date );
		recordService.updateById(record);
        return R.ok();
    }

    /**
     * 删除
     */
    @RequestMapping("/delete")
    public R delete(@RequestBody Integer[] ids){
		recordService.removeByIds(Arrays.asList(ids));

        return R.ok();
    }

    /**
     * 单删除
     */
    @RequestMapping("/deletes/{id}")
    public R deletes(@PathVariable("id") Integer id){
        RecordEntity recordEntity = recordService.getById( id );
        recordEntity.setStart( 1 );
        Date date = new Date();
        recordEntity.setDeletedAt( date );
        recordService.updateById( recordEntity );
        return R.ok();
    }

}
